package com.dtp.common.properties;

import com.dtp.common.constant.DynamicTpConst;
import com.dtp.common.entity.DtpExecutorProps;
import com.dtp.common.entity.NotifyPlatform;
import com.dtp.common.entity.TpExecutorProps;
import com.google.common.collect.Lists;
import lombok.Data;
import lombok.extern.slf4j.Slf4j;
import org.springframework.boot.context.properties.ConfigurationProperties;

import java.util.List;

import static com.dtp.common.em.CollectorTypeEnum.MICROMETER;

/**
 * 动态线程池的配置文件信息
 *
 * @author yanhom
 * @since 1.0.0
 *
 * @remark muse
 **/
@Slf4j
@Data
@ConfigurationProperties(prefix = DynamicTpConst.MAIN_PROPERTIES_PREFIX) // "spring.dynamic.tp"
public class DtpProperties {
    private boolean enabled = true;         // 是否启用DynamicTp
    private boolean enabledBanner = true;   // 是否打印Banner
    private Nacos nacos;                    // Nacos配置信息
    private Apollo apollo;                  // Apollo配置信息
    private Zookeeper zookeeper;            // Zookeeper配置信息
    private Etcd etcd;                      // Etcd配置信息
    private String configType = "yml";      // 配置文件类型
    private boolean enabledCollect = false; // 是否开启指标收集
    private List<String> collectorTypes = Lists.newArrayList(MICROMETER.name()); // 指标收集器类型，默认为日志记录
    private String logPath;                     // Metrics日志存储路径，仅用于“日志”类型
    private int monitorInterval = 5;            // 监控间隔，时间单位(s)
    private List<DtpExecutorProps> executors;   // 线程池配置项
    private List<NotifyPlatform> platforms;     // 通知平台配置项
    private TpExecutorProps tomcatTp;           // Tomcat工作线程池
    private TpExecutorProps jettyTp;            // Jetty线程池
    private TpExecutorProps undertowTp;         // Undertow线程池
    private List<TpExecutorProps> dubboTp;      // Dubbo线程池
    private List<TpExecutorProps> hystrixTp;    // Hystrix线程池
    private List<TpExecutorProps> rocketMqTp;   // RocketMQ线程池
    private List<TpExecutorProps> grpcTp;       // Grpc线程池
    private List<TpExecutorProps> motanTp;      // Motan服务线程池
    private List<TpExecutorProps> okhttp3Tp;    // Okhttp3线程池
    private List<TpExecutorProps> brpcTp;       // Brpc线程池
    private List<TpExecutorProps> tarsTp;       // Tars线程池
    private List<TpExecutorProps> sofaTp;       // Sofa线程池
    private List<TpExecutorProps> rabbitmqTp;   // Rabbitmq线程池

    @Data
    public static class Nacos {
        private String dataId;
        private String group;
        private String namespace;
    }

    @Data
    public static class Apollo {
        private String namespace;
    }

    @Data
    public static class Zookeeper {
        private String zkConnectStr;
        private String configVersion;
        private String rootNode;
        private String node;
        private String configKey;
    }

    @Data
    public static class Etcd {
        private String endpoints;
        private String user;
        private String password;
        private String charset = "UTF-8";
        private boolean authEnable = false;
        private String authority = "ssl";
        private String key;
    }
}
